package com.smart.modal.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.annotation.RepeatSubmit;
import com.smart.common.BaseController;
import com.smart.entity.R;
import com.smart.modal.domain.bo.SysModelDataBo;
import com.smart.modal.domain.vo.SysModelDataVo;
import com.smart.modal.service.ISysModelDataService;
import com.smart.page.PageQuery;
import com.smart.page.TableDataInfo;
import com.smart.validate.AddGroup;
import com.smart.validate.EditGroup;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 系统模型配置信息
 *
 * @author LuckyBoy
 * @date 2025-11-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/server/modelData")
public class SysModelDataController extends BaseController {

    private final ISysModelDataService sysModelDataService;

    /**
     * 查询系统模型配置信息列表
     */
    @SaCheckPermission("system:modelData:list")
    @GetMapping("/list")
    public TableDataInfo<SysModelDataVo> list(SysModelDataBo bo, PageQuery pageQuery) {
        return sysModelDataService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出系统模型配置信息列表
     */
    @SaCheckPermission("system:modelData:export")
    @PostMapping("/export")
    public void export(SysModelDataBo bo, HttpServletResponse response) {
        List<SysModelDataVo> list = sysModelDataService.queryList(bo);
//        ExcelUtil.exportExcel(list, "系统模型配置信息", SysModelDataVo.class, response);
    }

    /**
     * 获取系统模型配置信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:modelData:query")
    @GetMapping("/{id}")
    public R<SysModelDataVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(sysModelDataService.queryById(id));
    }

    /**
     * 新增系统模型配置信息
     */
    @SaCheckPermission("system:modelData:add")
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysModelDataBo bo) {
        return toAjax(sysModelDataService.insertByBo(bo));
    }

    /**
     * 修改系统模型配置信息
     */
    @SaCheckPermission("system:modelData:edit")
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysModelDataBo bo) {
        return toAjax(sysModelDataService.updateByBo(bo));
    }

    /**
     * 删除系统模型配置信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:modelData:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(sysModelDataService.deleteWithValidByIds(List.of(ids), true));
    }
}
